# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Jakob Gahde <j5lx@fmail.co.uk>
# Contributor: Bastien "neitsab" Traverse <firstname [at] lastname [dot] email>
# Contributor: Icaro Perseo <icaroperseo[at]protonmail[dot]com>
# Contributor: Philipp 'TamCore' B. <philipp [at] tamcore [dot] eu>

pkgname=ghostwriter
pkgver=23.04.1
pkgrel=1
pkgdesc='Aesthetic, distraction-free Markdown editor'
arch=(x86_64)
url='https://ghostwriter.kde.org/'
license=(GPL3)
groups=(kde-applications kde-office)
depends=(hunspell qt5-webengine kxmlgui sonnet)
makedepends=(extra-cmake-modules kdoctools qt5-tools)
optdepends=('cmark: processing and rendering CommonMark'
            'mathjax: formula rendering in live preview'
            'pandoc: Pandoc supported Markdown flavors and export to various formats')
source=(https://download.kde.org/stable/release-service/$pkgver/src/$pkgname-$pkgver.tar.xz{,.sig})
sha256sums=('ac7182a7a3a4e0010f39969df9265fd0ddb5c22e9451ae3ccaee9489e0bc8f2c'
            'SKIP')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>

prepare() {
  cd $pkgname-$pkgver
  # Unbundle MathJax
  sed -i 's/typeof window.MathJax !==/typeof window.MathJax.typeset !==/' resources/preview.html
  sed -i 's|qrc:3rdparty/MathJax/bin/tex-svg-full.js|file:///usr/share/mathjax/tex-svg-full.js|' resources/preview.html
  sed -i '/MathJax/d' resources.qrc
}

build() {
  cmake -B build -S $pkgname-$pkgver \
    -DBUILD_TESTING=OFF
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
}
